package net.entelijan.cobean.data.literature;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ShowData {

	public ShowData() {
		super();
	}

	public static void main(String[] args) {
		ILitService s = createService();
		List<LitBook> books = s.loadAllBooks();
		System.out.println("---books-----------------------------------");
		for (LitBook b : books) {
			printObject(b, 0);
		}
		List<LitAuthor> authors = s.loadAllAuthors();
		System.out.println("---authors-----------------------------------");
		for (LitAuthor a : authors) {
			printObject(a, 0);
			List<LitBook> bs = a.getBooks();
			if (bs != null) {
				for (LitBook b : bs) {
					printObject(b, 1);
				}
			}
		}
	}

	private static void printObject(Object b, int depth) {
		for (int i = 0; i < depth; i++) {
			System.out.print(".   ");
		}
		System.out.println(b);
	}

	private static ILitService createService() {
		ApplicationContext ctx = new ClassPathXmlApplicationContext(
				"lit-service-ctx.xml");
		return (ILitService) ctx.getBean("inmem-service");
	}

}
